import Vue from "vue"
import Router from "vue-router"

Vue.use(Router)

import Layout from "@/layout"

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },
  {
    path: "/",
    component: Layout,
    redirect: "/userControl/menuControl",
    children: [
      // {
      //   path: "chart",
      //   name: "Chart",
      //   component: () => import("@/views/chart/index"),
      //   meta: {title: "平台概览", icon: "dashboard"}
      // }
    ]
  },
  {
    path: "/systemBuilding",
    component: Layout,
    children: [
      {
        path: "pcSystemBuildMenu",
        name: "pcSystemBuildMenu",
        meta: {
          activeMenu: "/systemBuilding/pcSystemBuilding"
        },
        hidden: true,
        component: () => import("@/views/systemBuilding/pcSystemBuilding/menu")
      }
    ]
  },
  {
    path: "/systemBuilding",
    component: Layout,
    children: [
      {
        path: "settingPeople",
        name: "settingPeople",
        meta: {
          activeMenu: "/systemBuilding/pcSystemBuilding"
        },
        hidden: true,
        component: () => import("@/views/systemBuilding/pcSystemBuilding/settingPeople")
      }
    ]
  },
  {
    path: "/systemBuilding",
    component: Layout,
    children: [
      {
        path: "pcSystemBuildLayout",
        name: "pcSystemBuildLayout",
        meta: {
          activeMenu: "/systemBuilding/pcSystemBuilding"
        },
        hidden: true,
        component: () => import("@/views/systemBuilding/pcSystemBuilding/layout")
      }
    ]
  },
  {
    path: "/systemBuilding",
    component: Layout,
    children: [
      {
        path: "settingCard",
        name: "settingCard",
        meta: {
          activeMenu: "/systemBuilding/pcSystemBuilding"
        },
        hidden: true,
        component: () => import("@/views/systemBuilding/pcSystemBuilding/settingCard")
      }
    ]
  }

]

const createRouter = () =>
  new Router({
    mode: 'hash',
    scrollBehavior: () => ({y: 0}), // 为了每次跳转路由页面都是在最顶部
    routes: constantRoutes
  })
const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
